#pragma once
#include <map>
#include <functional>

using namespace std;

namespace Core
{
	#define delegate(t, f) std::bind(f, t, std::tr1::placeholders::_1);

	class event
	{
	private:
		typedef function<void(void* e)> Handler;
		map<int, Handler> list;
		int id;

	public:
		event() : id(0) { }

		int operator +=(Handler f)
		{
			this->list[++id] = f;
			return id;
		}

		void operator -=(int id)
		{
			this->list.erase(id);
		}

		void operator()(void* e)
		{
			for each(auto f in list)
				f.second(e);
		}
	};
}